home *** CD-ROM | disk | FTP | other *** search
- /*
- -------------------------------------------------------------------------
- rg.c -- A program to restore a guest account after use.
- -------------------------------------------------------------------------
- version 1.0
- by Eric Celeste <efc@mit.edu>
- -------------------------------------------------------------------------
- This is a small program designed to be used as a LogoutHook on a
- user group machine. We like letting folks use the NeXT in the
- resource center, but find that they often trash the guest account
- and the next person to log in finds a tremendous mess. This program
- runs every time someone logs out of the machine and ensures that
- the guest account is set back to the state it was found in. It does
- this by recreating the guest account from a template account every
- time a user logs out of the machine. To make changes to the guest
- account permanently, you simply log into the template account and
- make the changes.
-
- To use this program:
-
- (1) Make sure you have both a guest account and a template account
- set up on your machine. If you don't know how to create these
- accounts, then you should probably not be trying to use this
- program!
-
- (2) Change the defines to meet the conditions of your environment
- and recompile this code.
- (a) Change the defines.
- (b) Save this file.
- (c) Open a terminal window.
- (d) Change directory "cd" to the directory with this file in it.
- (e) Compile this file "cc rg.c -o rg".
-
- (3) Strip the executable file: "strip rg".
-
- (4) Make sure you are root by "su" or loging into the root account.
-
- (5) Copy this file to /usr/local/bin so everyone knows where to
- find it: "cp rg /usr/local/bin/rg".
-
- (6) Change the file modes so that only root can execute it:
- "chmod 700 /usr/local/bin/rg".
-
- (7) Add a line to the defaults database that will execute this
- command every time a user logs out of an account:
- "dwrite loginwindow LogoutHook /usr/local/bin/rg".
-
- (8) Reboot the machine so that the new loginwindow default is used.
-
- This does slow down logging out a bit, but for a machine in a public
- place, that price is well worth it.
-
- By the way, this program can be run from the Terminal window by
- root for debugging purposes. It is probably a good idea to do this
- before installing it as the LogoutHook, just to make sure it does
- what you expect!
- -------------------------------------------------------------------------
- */
-
- #import <stdio.h>
- #import <stdlib.h>
-
- #define GUEST_ACCOUNT_NAME "guest"
- #define GUEST_ACCOUNT_DIRECTORY "/Users"
- #define GUEST_ACCOUNT_OWNER "guest.other"
- #define TEMPLATE_ACCOUNT_NAME "guesttemplate"
- #define TEMPLATE_ACCOUNT_DIRECTORY "/usr/local"
-
- void main(int argc, char *argv[]) {
-
- char command[200];
-
- sprintf(command,"/bin/cp -r %s/%s %s",
- TEMPLATE_ACCOUNT_DIRECTORY,
- TEMPLATE_ACCOUNT_NAME,
- GUEST_ACCOUNT_DIRECTORY
- );
- if (system(command)) {
- printf("rg: error while copying template account\n");
- exit(1);
- } else {
- sprintf(command,"/bin/rm -r %s/%s",
- GUEST_ACCOUNT_DIRECTORY,
- GUEST_ACCOUNT_NAME
- );
- if (system(command)) {
- printf("rg: error while removing dirty guest account\n");
- exit(1);
- } else {
- sprintf(command,"/bin/mv %s/%s %s/%s",
- GUEST_ACCOUNT_DIRECTORY,
- TEMPLATE_ACCOUNT_NAME,
- GUEST_ACCOUNT_DIRECTORY,
- GUEST_ACCOUNT_NAME
- );
- if (system(command)) {
- printf("rg: error while moving template to guest account\n");
- exit(1);
- } else {
- sprintf(command,"/usr/etc/chown -f -R %s %s/%s",
- GUEST_ACCOUNT_OWNER,
- GUEST_ACCOUNT_DIRECTORY,
- GUEST_ACCOUNT_NAME
- );
- if (system(command)) {
- printf("rg: error while change guest account ownership\n");
- exit(1);
- } else {
- // no error reported
- exit(0);
- }
- }
- }
- }
-
- printf("rg: unknown error\n");
- exit(1);
- }